import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RouterModule, Routes } from '@angular/router';

//导入路由守卫
import { AuthGuard } from "./auth-guard.service"

// ++1、路由模块初始化
// ++2、配置路由表请求某个路径的时候，导航到某个组件
// ++3、配置路由出口及路由导航链接

// 4、导入路由组件
import { SiginComponent } from './sigin/sigin.component'
import { SiginupComponent } from './siginup/siginup.component'

import { LayoutComponent } from './layout/layout.component'

//用户列表操作
import { ComtactListComponent } from './comtact-list/comtact-list.component'
import { ComtactEditComponent } from './comtact-edit/comtact-edit.component'
import { ComtactNewComponent } from './comtact-new/comtact-new.component'

//标签管理操作
import { TagEditComponent } from './tag-edit/tag-edit.component'
import { TagListComponent } from './tag-list/tag-list.component'
import { TagNewComponent } from './tag-new/tag-new.component'

// 5、配置路由导航数组对象（路由表）
const routes: Routes = [
  {//配置重定向
    path: '',
    redirectTo: '/comtact',//当请求根路径时，跳转到ComtactListComponent组件
    pathMatch: 'full'    //必须设置完全匹配时才做重定向
  },
  {//跳转到主页
    path: 'layout',
    component: LayoutComponent
  },
  {//主页用户列表
    path: 'comtact',
    component: LayoutComponent,
    canActivate: [AuthGuard],
    children: [
      {
        path: '',
        component: ComtactListComponent
      },
      {
        path: 'new',
        component: ComtactNewComponent
      },
      {
        path: 'edit/:id',
        component: ComtactEditComponent
      }
    ]
  },
  {//标签管理列表
    path: 'tag',
    canActivate: [AuthGuard],
    component: LayoutComponent,
    children: [
      {
        path: '',
        component: TagListComponent
      },
      {
        path: 'tagedit',
        component: TagEditComponent
      },
      {
        path: 'tagnew',
        component: TagNewComponent
      }
    ]
  },
  {//登录
    path: 'sigin',
    component: SiginComponent
  },
  {//注册
    path: 'siginup',
    component: SiginupComponent
  }
]

// 将路由对象导入到路由模块
@NgModule({
  imports: [
    RouterModule.forRoot(routes)
  ],
  exports: [RouterModule],
  providers: [AuthGuard]
})

export class AppRoutingModule { }
